<?php

namespace app\backend\validator;

use think\Validate;

class UpdPaymentSettingValidator extends Validate
{
    protected $rule = [
        'id'            => 'require',
        'status'        => 'in:0,1',
        'priority'      => 'number',
        'quota'         => 'array',
        'pay_url'       => 'checkUrl',
    ];

    protected $message = [
        'id.require' => '支付设置ID必填',
        'status.int' => '未知支付状态类型',
        'priority.number' => '序号必须是大于零的整数',
        'quota.array' => '支付面额必须是数组类型',
    ];

    protected function checkUrl($value)
    {
        if(isset($value)) {
            return 0 === strpos($value, 'http') ? true : '支付链接必须以http开头';
        }
    }
}